<!DOCTYPE html>
<html>
  <head>
    <title><%= title %></title>
    <link rel='stylesheet' href='/stylesheets/style.css' />
  </head>
  <body>
<div>
<div>用户名:  <input id="username"> </div>
<div>密码: <input type="password" id="password"></div>
<div>年龄 <input type="number" id="age"></div>
<div><button id="register">注册</button></div>
</div>
<hr>  

<div>
<button id="update">更新</button>
<button id="delete">删除</button>
</div>

<script>
    var update=document.querySelector("#update")
    var mydelete=document.querySelector("#delete")
    var username=document.querySelector("#username")
    var password=document.querySelector("#password")
    var age=document.querySelector("#age")
    var register=document.querySelector("#register")

    register.onclick=()=>{
        fetch("/api/user/add",{
      method:"POST",
      body:JSON.stringify({
        username:username.value,
        password:password.value,
        age:age.value
      }),
      headers:{
        "Content-Type":"application/json"
      }
    }).then(res=>res.json()).then(res=>{
      console.log(res);
    })
    }

    
    update.onclick=()=>{
        fetch("/api/user/update/639b0fd614ce1ba3577ed41f",{
      method:"POST",
      body:JSON.stringify({
        username:"修改的名字",
        password:"修改的密码",
        age:12
      }),
      headers:{
        "Content-Type":"application/json"
      }
    }).then(res=>res.json()).then(res=>{
      console.log(res);
    })
    }

    mydelete.onclick=()=>{
        fetch("/api/user/delete/639b0fd614ce1ba3577ed41f").then(res=>res.json()).then(res=>{
      console.log(res);
    })
    }
  fetch("/api/user/list").then(res=>res.json()).then(res=>{
    console.log(res);
  })
  
</script>
  </body>
</html>
